package com.zetyun.tiger.format.date.compact;

import com.zetyun.rt.meta.annotation.ActionMeta;
import com.zetyun.rt.sdk.action.MapAction;
import com.zetyun.rt.sdk.model.RtEvent;
import com.zetyun.rt.sdk.operator.OperatorContext;
import com.zetyun.tiger.format.date.SpecialDateFormatUtil;

import java.util.Map;
import java.util.Objects;

import static com.zetyun.tiger.format.date.FormatConstant.*;


@ActionMeta(
        id = "tiger.xbus-date-format",
        tags = {"formatter"},
        category = "map",
        name = "XbusDateFormat",
        status = ActionMeta.Status.PUBLIC,
        description = "Xbus系统 表统一日期格式,无时间日期字段，取系统时间字段为事件时间"
)
public class XBusDateFormatAction extends MapAction {


    @Override
    public RtEvent apply(RtEvent in) throws Exception {


        long procTs = System.currentTimeMillis();
        String currentSystemDate = SpecialDateFormatUtil.toYmdHms(procTs);
        in.setField(RT_PROC_TMS, procTs);
        in.setField(RT_PROC_TIME, currentSystemDate);


        in.setField(RT_EVENT_TMS, procTs);
        in.setField(RT_EVENT_TIME, currentSystemDate);
        in.setField(RT_EVENT_DATE, SpecialDateFormatUtil.day(currentSystemDate));
//        in.setField(RT_EVENT_HOUR, SpecialDateFormatUtil.hour(currentSystemDate));
//        in.setField(RT_EVENT_MINU, SpecialDateFormatUtil.minute(currentSystemDate));


        in.setField(RT_EVENT_TYPE, in.getField("op_"));
        in.removeField("op_");
        return in;
    }
}
